package vboot.app.module.te.prod.test;

import vboot.app.module.te.prod.cate.TeProdCate;
import vboot.app.module.te.prod.cate.TeProdCateService;
import vboot.core.common.api.R;
import vboot.core.common.dao.Sqler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("te/prod/test")
public class TeProdTestApi {

    //分页特性分类
    @GetMapping
    public R get(String name) {
        Sqler sqler = new Sqler("te_prod_test");
        sqler.addLike("t.name", name);
        sqler.addSelect("t.notes");
        return R.ok(service.findPageData(sqler));
    }

    @GetMapping("list")
    public R getList() {
        return R.ok(service.findAll());
    }

    //查询单个分类
    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        TeProdCate cate = service.findOne(id);
        return R.ok(cate);
    }

    //新增分类
    @PostMapping
    public R post(@RequestBody TeProdCate cate) {
        return R.ok(service.insert(cate));
    }

    //修改分类
    @PutMapping
    public R put(@RequestBody TeProdCate cate) {
        return R.ok(service.update(cate));
    }

    //删除分类
    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @Autowired
    private TeProdCateService service;

}
